package by.cooker.chat.logic;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;

/**
 * @author cooker
 */
public class Sender
{
	private BufferedWriter writer = null;

	/**
	 * Sender constructor.
	 * 
	 * @throws IOException
	 *             - if I/O problem.
	 */
	public Sender() throws IOException
	{
		writer = new BufferedWriter(new OutputStreamWriter(Client.getClient()
				.getSocket().getOutputStream()));
	}

	/**
	 * Send message to server.
	 * 
	 * @param msg
	 *            - message.
	 */
	public synchronized void sendMsg(String message)
	{
		try
		{
			writer.write(message);
			writer.write("\n");
			writer.flush();
		} catch (IOException e)
		{
			e.printStackTrace();
		}
	}
}
